using Infrastructure.Attribute;
using Infrastructure.Extensions;
using ZR.Model;
using ZR.Model.Dto;
using ZR.Repository;
using System.Linq;
using ZR.Service.IService.ProductionControl;
using ZR.Model.Models.ProductionControl;
using ZR.Model.Dto.Business.ProductionControl;

namespace ZR.Service.Service.ProductionControl
{
    /// <summary>
    /// 设备配方管理Service业务层处理
    /// </summary>
    [AppService(ServiceType = typeof(IRecipeConfigService), ServiceLifetime = LifeTime.Transient)]
    public class RecipeConfigService : BaseService<RecipeConfig>, IRecipeConfigService
    {
        /// <summary>
        /// 查询设备配方管理列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        public PagedInfo<RecipeConfigDto> GetList(RecipeConfigQueryDto parm)
        {
            var predicate = QueryExp(parm);

            var response = Queryable()
                .Where(predicate.ToExpression())
                .ToPage<RecipeConfig, RecipeConfigDto>(parm);

            return response;
        }

        /// <summary>
        /// 获取详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public RecipeConfig GetInfo(int Id)
        {
            var response = Queryable()
                .Where(x => x.Id == Id)
                .First();

            return response;
        }

        /// <summary>
        /// 添加设备配方管理
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public RecipeConfig AddRecipeConfig(RecipeConfig model)
        {
            return Insertable(model).ExecuteReturnEntity();
        }

        /// <summary>
        /// 修改设备配方管理
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int UpdateRecipeConfig(RecipeConfig model)
        {
            return Update(model, true);
        }

        /// <summary>
        /// 查询导出表达式
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        private static Expressionable<RecipeConfig> QueryExp(RecipeConfigQueryDto parm)
        {
            var predicate = Expressionable.Create<RecipeConfig>();

            return predicate;
        }
    }
}